<?php
namespace Admin\Controller;
use Think\Controller;
class UsersController extends Controller {
   public function userList(){
        $usersModel=M('user'); //实例化模型对象 user 表名
		$users=$usersModel->order('user_id desc')->select(); //查询
		$this->users=$users; //volist name
		// dump ($users); 
		$this->display();
}
 public function deluser(){
        // dump($_GET);
        $usersModel=M('user');
        $uid=$_GET['uid'];
        //var_dump($uid);
        $res=$usersModel->where("user_id=$uid")->find();
        //var_dump($res);
        $photoPath=realpath("./Public/Uploads/userphoto".$res['photo']);
        unlink($photoPath);
        if ($usersModel->where("user_id=$uid")->delete()) {
        	$this->success('删除成功');
        }else{
        	$this->error('删除失败');
        }

    }
public function state(){
	$usersModel=M('users');
	$uid=$_GET['uid'];
	$usersModel->state=1;
	if(false!==$usersModel->where("uid=$uid")->save()){
			$this->success('封号成功');
		}else{
			$this->error('封号失败');
		}
}
public function attention(){
        $usersModel=M('attention'); //实例化模型对象 user 表名
        $user_id=$_GET['id'];
        $users=$usersModel->where("user_id=$user_id")->select(); //查询
        $this->users=$users; //volist name
        // dump ($users); 
        $this->display();
}
public function delattention(){
        // dump($_GET);
        $usersModel=M('attention');
        $uid=$_GET['uid'];
        //var_dump($uid);
        $res=$usersModel->where("attention_id=$uid")->find();
        //var_dump($res);
        $photoPath=realpath("./Public/Uploads/userphoto".$res['photo']);
        unlink($photoPath);
        if ($usersModel->where("attention_id=$uid")->delete()) {
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }

    }

    public function post(){
        $usersModel=M('post'); //实例化模型对象 user 表名
        $user_id=$_GET['id'];
        $users=$usersModel->where("post_id=$user_id")->select(); //查询
        $this->users=$users; //volist name
        // dump ($users); 
        $this->display();
}
public function delpost(){
        // dump($_GET);
        $usersModel=M('post');
        $uid=$_GET['uid'];
        //var_dump($uid);
        $res=$usersModel->where("post_id=$uid")->find();
        //var_dump($res);
        $photoPath=realpath("./Public/Uploads/userphoto".$res['photo']);
        unlink($photoPath);
        if ($usersModel->where("post_id=$uid")->delete()) {
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }

    }
}